﻿using System;
using UnityEngine;

namespace WentStateMachine
{
    [Serializable]
    public class Parameter
    {
        private string _name;
        public string name {
            get {
                return _name;
            }
            set {
                _nameHash = Helper.ScriptingStringToCRC32(value);
                _name = value;
            }
        }

        [SerializeField] private int _nameHash;
        public int nameHash {
            get {
                return _nameHash;
            }
            set
            {
                _nameHash = value;
            }
        }

        [SerializeField] private ParameterType _type;
        public ParameterType type {
            get {
                return _type;
            }
            set {
                _type = value;
            } 
        }
        [SerializeField] private float _defaultFloat;
        public float defaultFloat {
            get
            {
                return _defaultFloat;
            }
            set
            {
                _defaultFloat = value;
            }
        }
        [SerializeField] private int _defaultInt;
        public int defaultInt {
            get
            {
                return _defaultInt;
            }
            set
            {
                _defaultInt = value;
            }
        }
        [SerializeField] private bool _defaultBool;
        public bool defaultBool {
            get
            {
                return _defaultBool;
            }
            set
            {
                _defaultBool = value;
            }
        }

        public bool Equal(float threshold)
        {
            switch (type)
            {
                case ParameterType.Float:
                    return defaultFloat == threshold;
                case ParameterType.Int:
                    return ((float)defaultInt) == threshold;
                default:
                    return false;
            }
        }

        public bool NotEqual(float threshold)
        {
            switch (type)
            {
                case ParameterType.Float:
                    return defaultFloat != threshold;
                case ParameterType.Int:
                    return ((float)defaultInt) != threshold;
                default:
                    return false;
            }
        }

        public bool Greater(float threshold)
        {
            switch (type)
            {
                case ParameterType.Float:
                    return defaultFloat > threshold;
                case ParameterType.Int:
                    return ((float)defaultInt) > threshold;
                default:
                    return false;
            }
        }

        public bool Less(float threshold)
        {
            switch (type)
            {
                case ParameterType.Float:
                    return defaultFloat < threshold;
                case ParameterType.Int:
                    return ((float)defaultInt) < threshold;
                default:
                    return false;
            }
        }
    }
}
